{{- define "main" }}

{{- if (and .Site.Params.profileMode.enabled .IsHome) }}
{{- partial "index_profile.html" . }}
{{- else }} {{/* if not profileMode */}}

{{- if not .IsHome | and .Title }}
<header class="page-header">
  {{- partial "breadcrumbs.html" . }}
  <h1>{{ .Title }}</h1>
  {{- if .Description }}
  <div class="post-description">
    {{ .Description | markdownify }}
  </div>
  {{- end }}
</header>
{{- end }}

{{- if .Content }}
<div class="post-content">
  {{- if not (.Param "disableAnchoredHeadings") }}
  {{- partial "anchored_headings.html" .Content -}}
  {{- else }}{{ .Content }}{{ end }}
</div>
{{- end }}

{{- $pages := union .RegularPages .Sections }}

{{- if .IsHome }}
{{- $pages = where site.RegularPages "Type" "in" site.Params.mainSections }}
{{- end }}

{{- $paginator := .Paginate $pages }}

{{- if and .IsHome .Site.Params.homeInfoParams (eq $paginator.PageNumber 1) }}
{{- partial "home_info.html" . }}
{{- end }}

{{- $term := .Data.Term }}
{{- range $index, $page := $paginator.Pages }}

{{- $class := "post-entry" }}

{{- $user_preferred := or .Site.Params.disableSpecial1stPost .Site.Params.homeInfoParams }}
{{- if (and $.IsHome (eq $paginator.PageNumber 1) (eq $index 0) (not $user_preferred)) }}
{{- $class = "first-entry" }}
{{- else if $term }}
<!-- {{- $class = "post-entry tag-entry" }} -->
{{- $class = "post-entry" }}
{{- end }}

<article class="{{ $class }}">
  <div class="post-info">
    <header class="entry-header">
      <h2>
        {{- .Title }}
        {{- if .Draft }}<sup><span class="entry-isdraft">&nbsp;&nbsp;[draft]</span></sup>{{- end }}
      </h2>
    </header>
    {{- if (ne (.Param "hideSummary") true) }}
    <section class="entry-content">
      <p>
        {{- if .Description }}
        {{ .Description }}
        {{- else }}
        {{ .Summary | plainify | htmlUnescape }}
        {{- end }}
        {{ if .Truncated }}...{{ end }}
      </p>
    </section>
    {{- end }}
    {{- if not (.Param "hideMeta") }}
    <footer class="entry-footer">
      {{- partial "post_meta.html" . -}}
    </footer>
    {{- end }}
  </div>
  {{- $isHidden := (.Site.Params.cover.hidden | default .Site.Params.cover.hiddenInList) }}
  {{- partial "cover.html" (dict "cxt" . "IsHome" true "isHidden" $isHidden) }}
  <a class="entry-link" aria-label="post link to {{ .Title | plainify }}" href="{{ .Permalink }}"></a>
</article>
{{- end }}

{{- if gt $paginator.TotalPages 1 }}
<footer class="page-footer">
  <nav class="pagination">
    <!--    {{- if $paginator.HasPrev }}-->
    <!--    <a class="prev" href="{{ $paginator.Prev.URL | absURL }}">{{ i18n "prev_page" }}</a>-->
    <!--    {{- end }}-->

    {{- if not (eq $paginator.PageNumber 1) }}
    <span class="numFirst">
        <a class="pageFirst" href="{{ $paginator.First.URL | absURL }}">{{ "1" }}</a>
      </span>
      {{- if not (eq $paginator.PageNumber 2) }}
          &nbsp;...&nbsp;
          <span class="numPrev">
              <a class="pagePrev" href="{{ $paginator.Prev.URL | absURL }}">{{ sub $paginator.PageNumber 1 }}</a>
          </span>
        {{- end }}
    {{- end }}

    <span class="pageNum">
      <a class="pageNow" href="{{ $paginator.URL | absURL }}">{{ $paginator.PageNumber }}</a>
    </span>

    {{- if not (eq $paginator.PageNumber $paginator.TotalPages) }}
    {{- if not (eq $paginator.PageNumber ( sub $paginator.TotalPages 1)) }}
    <span class="numNext">
      <a class="pageNext" href="{{ $paginator.Next.URL | absURL }}">{{ add $paginator.PageNumber 1 }}</a>
    </span>
    &nbsp;...&nbsp;
    {{- end }}
    <span class="numLast">
        <a class="pageLast" href="{{ $paginator.Last.URL | absURL }}">{{ $paginator.TotalPages }}</a>
      </span>
    {{- end }}

    <!--    {{- if $paginator.HasNext }}-->
    <!--    <a class="next" href="{{ $paginator.Last.URL | absURL }}">{{ i18n "next_page" }}</a>-->
    <!--    {{- end }}-->
  </nav>
</footer>
{{- end }}

{{- end }}{{/* end profileMode */}}

{{- end }}{{- /* end main */ -}}
